class Solution:
    def isRectangleCover(self, rectangles) -> bool:
        minx, miny, maxx, maxy = rectangles[0]
        sumArea = 0
        pointHash = set()
        for i in rectangles:
            minx = min(minx, i[0])
            miny = min(miny, i[1])
            maxx = max(maxx, i[2])
            maxy = max(maxy, i[3])
            sumArea = sumArea + (i[2] - i[0]) * (i[3] - i[1])
            for x in [(i[0],i[1]),(i[2],i[3]),(i[0],i[3]),(i[2],i[1])]:
                if x in pointHash:
                    pointHash.remove(x)
                else:
                    pointHash.add(x)
        if (maxy - miny) * (maxx - minx) != sumArea:
            return False
        if len(pointHash) == 4 and (minx,miny) in pointHash and (minx,maxy) in pointHash and (maxx,miny) in pointHash and (maxx,maxy) in pointHash:
            return True
        return False


if __name__ == '__main__':
    so = Solution()
    rectangles = [[1,1,3,3],[3,1,4,2],[3,2,4,4],[1,3,2,4],[2,3,3,4]]
    r = so.isRectangleCover(rectangles)
    print(r)
